﻿package manager
{
    import __AS3__.vec.*;
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.it.plugin.*;
    import com.sh.game.loader.*;
    import com.sh.game.net.*;
    import com.sh.game.util.*;
    import consts.*;
    import flash.geom.*;
    import flash.utils.*;
    import morn.core.components.*;
    import pluginfw.*;
    import pluginfw.nio.*;
    import view.*;
    import view.message.*;
    import view.mornExtends.*;
    import view.uilt.*;

    public class PluginManager extends Object
    {
        private var _pluginContainer:Object;
        private var _flashUiContainer:Object;
        private var _alertCon:Object;
        private var cfgClass:Class;
        private var _cfg:Dictionary;
        private var _plugins:Dictionary;
        private var _openDic:Dictionary;
        private var _pluginHandlers:Dictionary;
        private var tempPs:Dictionary;
        private var tempTPs:Dictionary;
        private var tempdata:Dictionary;
        private var _openArr:Array;
        private var _localPlugins:Object;
        private var announceTime:int = 0;
        private var _firstopen:int = 0;
        private var _firstopenArr:Array;
        private var _openLevel:Object;
        private var relation:Object;
        private var _loadnames:Vector.<String>;
        private var _isloading:Boolean = false;
        private var _cmdCD:int = 0;
        private var messagelist:Array;
        private var _lastwarning:int = 0;
        private static var _instance:PluginManager;
        private static const UNLOAD:String = "unload";
        private static const OPEN:String = "open";
        private static const CLOSE:String = "close";

        public function PluginManager()
        {
            this.cfgClass = PluginManager_cfgClass;
            this._openDic = new Dictionary();
            this.tempPs = new Dictionary();
            this.tempTPs = new Dictionary();
            this.tempdata = new Dictionary();
            this._openArr = [];
            this._firstopenArr = [];
            this.relation = {roletwo:["role"], bag:["role", "warehouse", "stallage", "shop", "business", "zbhsy", "guanwei", "shenlu", "wing", "npcdialog", "qhtips"]};
            this._loadnames = new Vector.<String>;
            this.messagelist = [];
            return;
        }// end function

        public function get flashUiContainer() : Object
        {
            return this._flashUiContainer;
        }// end function

        public function get alertContainer() : Object
        {
            return this._alertCon;
        }// end function

        public function init(param1:Object, param2:Object, param3:Object, param4:Object) : void
        {
            var _loc_8:Object = null;
            var _loc_9:Boolean = false;
            var _loc_10:Object = null;
            var _loc_11:Trie = null;
            var _loc_12:Array = null;
            var _loc_13:Object = null;
            var _loc_14:AppDialog = null;
            this._flashUiContainer = param2;
            ModelProxy.change("data", "opendPlugin", this._openDic);
            this._alertCon = param4;
            this._cfg = new Dictionary();
            this._plugins = new Dictionary();
            var _loc_5:* = CSVDataUtil.listData(new this.cfgClass());
            var _loc_6:* = new PluginGroupHandler();
            var _loc_15:* = param1;
            this._localPlugins = param1;
            var _loc_7:* = _loc_15;
            for each (_loc_8 in _loc_5)
            {
                
                _loc_9 = int(_loc_8.noesc) != 1;
                _loc_8.esc = _loc_9;
                _loc_8.width = int(_loc_8.width);
                _loc_8.height = int(_loc_8.height);
                _loc_8.moveeff = int(_loc_8.moveeff);
                _loc_8.openaction = int(_loc_8.openaction);
                this._cfg[_loc_8.name] = _loc_8;
                this._plugins[_loc_8.name] = UNLOAD;
                if (!HandlerManager.instance.hasgetHandler(_loc_8.name))
                {
                    Server.instance.addHandler(ConnectType.SYSTEM, _loc_8.group, _loc_6);
                }
                else
                {
                    HandlerManager.instance.addHandler(_loc_8.name);
                }
                if (_loc_7[_loc_8.name])
                {
                    _loc_10 = new _loc_7[_loc_8.name];
                    this.onComplete({name:_loc_8.name, module:_loc_10}, true);
                }
            }
            Server.instance.addHandler(ConnectType.SYSTEM, 61, _loc_6);
            Server.instance.addHandler(ConnectType.SYSTEM, 121, _loc_6);
            if (!ModelProxy.getValue("data", "debugPlugin"))
            {
                _loc_11 = new Trie();
                _loc_12 = ConfigDictionary.data.face;
                for each (_loc_13 in _loc_12)
                {
                    
                    _loc_11.add(_loc_13.protocol);
                }
                ModelProxy.change("data", "chatTrie", _loc_11);
                _loc_14 = new AppDialog();
                PluginManager.instance.openPlugin("chatFlash", new Point(100, this._flashUiContainer.stage.stageHeight - 180));
                ModelProxy.change("chat", "addsysmsg", ConfigDictionary.data.announce[263].text);
                setInterval(this.doAnnounce, 60000);
            }
            return;
        }// end function

        private function doAnnounce() : void
        {
            var _loc_1:Object = null;
            var _loc_2:int = 0;
            var _loc_3:Array = null;
            var _loc_4:String = null;
            var _loc_5:Array = null;
            var _loc_6:String = this;
            var _loc_7:* = this.announceTime + 1;
            _loc_6.announceTime = _loc_7;
            if (this.announceTime % 3 == 0)
            {
                _loc_2 = UserData.getUserData("level");
                if (_loc_2 > 60)
                {
                    _loc_3 = [265, 266, 267, 268, 269, 271];
                }
                else if (_loc_2 > 50)
                {
                    _loc_3 = [265, 266, 267, 269, 271];
                }
                else if (_loc_2 > 40)
                {
                    _loc_3 = [265, 266, 267, 271];
                }
                else if (_loc_2 > 30)
                {
                    _loc_3 = [266, 271];
                }
                else if (_loc_2 > 20)
                {
                    _loc_3 = [266];
                }
                if (_loc_3)
                {
                    ModelProxy.change("chat", "addsysmsg", ConfigDictionary.data.announce[_loc_3[int(Math.random() * _loc_3.length)]].text.replace(/\|""\|/gi, ","));
                }
            }
            if (UserData.getUserData("level") >= 65)
            {
                switch(int(ModelProxy.getValue("data", "openday")) + 1)
                {
                    case 1:
                    {
                        this.wzadMsg();
                        setTimeout(this.wzadMsg, 2000);
                        break;
                    }
                    case 2:
                    {
                        if (this.announceTime % 2 == 0)
                        {
                            this.wzadMsg();
                            setTimeout(this.wzadMsg, 2000);
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            if (this.announceTime % 30 == 0)
            {
                _loc_4 = ConfigDictionary.data.announce[278].text;
                _loc_1 = ConfigDictionary.data.sysnpc[121];
                _loc_5 = [_loc_1.x, _loc_1.y, _loc_1.stageid, _loc_1.npcid];
                ModelProxy.change("chat", "addsysmsg", StringUtil.substitute(_loc_4.replace(/\|""\|/gi, ","), _loc_5));
            }
            return;
        }// end function

        public function wzadMsg() : void
        {
            var _loc_1:Array = ["暗之沃玛教主", "暗之腐烂尸王", "暗之触龙邪神", "暗之祖玛教主", "暗之牛魔大帝", "暗之赤月恶魔", "暗之虹魔教主", "暗之赤焰鹰魔", "暗之黄泉教主", "暗之野猪大帝"];
            var _loc_2:* = ConfigDictionary.data.sysnpc[151];
            var _loc_3:Array = [_loc_1[int(Math.random() * 10)], "未知暗殿", _loc_2.x, _loc_2.y, _loc_2.stageid, _loc_2.npcid];
            ModelProxy.change("chat", "addsysmsg", StringUtil.substitute(ConfigDictionary.data.announce[233].text.replace(/\|""\|/gi, ","), _loc_3));
            return;
        }// end function

        public function showFcm() : void
        {
            return;
        }// end function

        public function createPluginControl(param1:String, param2:Class) : void
        {
            var _loc_3:* = Control.create(param2, null);
            ModelProxy.addObserver(param1, _loc_3);
            return;
        }// end function

        private function getContainer(param1:int) : Object
        {
            var _loc_2:Object = null;
            switch(param1)
            {
                case UIContainerType.MAINUI:
                {
                    break;
                }
                case UIContainerType.POPUP:
                {
                    break;
                }
                case UIContainerType.TIPS:
                {
                    break;
                }
                case UIContainerType.FlashUI:
                {
                    _loc_2 = this.flashUiContainer;
                    break;
                }
                case UIContainerType.FlashAlert:
                {
                    _loc_2 = this._alertCon;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public function checkOpenLevel(param1:String, param2:int = 0) : Object
        {
            var _loc_3:Object = null;
            if (!this._openLevel)
            {
                this._openLevel = ConfigDictionary.data.openlevel;
            }
            if (this._openLevel[param1] && this._openLevel[param1][param2])
            {
                _loc_3 = this._openLevel[param1][param2];
                if (!ItemUilt.checkUserLevelRein(_loc_3.level, _loc_3.rein))
                {
                    return _loc_3;
                }
            }
            return null;
        }// end function

        public function limitError(param1:Object) : void
        {
            ItemUilt.ErrortipsForLevel(param1.level, param1.rein, param1.pageName);
            return;
        }// end function

        public function openPlugin(param1:String, param2:Point, param3:Object = null, param4:Point = null, param5:Boolean = true) : void
        {
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            if (param1 == "guanwei")
            {
                _loc_6 = int(GlobalLayer.instance.root.stageWidth / 2 - 550 + 60);
                _loc_7 = int(GlobalLayer.instance.root.stageHeight / 2 - 320);
                if (_loc_6 < 0)
                {
                    _loc_6 = 0;
                }
                param4 = new Point(_loc_6, _loc_7);
            }
            if (param5)
            {
                _loc_8 = this.checkOpenLevel(param1, int(param3));
                if (_loc_8)
                {
                    this.limitError(_loc_8);
                    return;
                }
            }
            this.openPluginF(param1, param2, param3, param4);
            return;
        }// end function

        private function isbaifuhd() : Boolean
        {
            var _loc_5:int = 0;
            var _loc_6:Date = null;
            var _loc_7:Date = null;
            var _loc_8:Date = null;
            var _loc_1:* = ConfigDictionary.data.activitytime;
            var _loc_2:* = ModelProxy.getValue("data", "openday") + 1;
            var _loc_3:* = int((ModelProxy.getValue("data", "servertime") + Number(getTimer())) / 1000);
            var _loc_4:* = _loc_1[27];
            switch(int(_loc_4.timetype))
            {
                case 1:
                {
                    if (_loc_2 >= _loc_4.opentime && _loc_2 <= _loc_4.overtime)
                    {
                        return true;
                    }
                    break;
                }
                case 2:
                {
                    if (_loc_3 >= _loc_4.opentimestr / 1000 && _loc_3 <= _loc_4.overtimestr / 1000)
                    {
                        return true;
                    }
                    break;
                }
                case 3:
                {
                    if (++ModelProxy.getValue("data", "hefuday") >= _loc_4.opentime && ++ModelProxy.getValue("data", "hefuday") <= _loc_4.overtime)
                    {
                        return true;
                    }
                    break;
                }
                case 4:
                {
                    if (_loc_2 >= _loc_4.opentime && _loc_2 <= _loc_4.overtime)
                    {
                        if (_loc_3 >= _loc_4.opentimestr / 1000 && _loc_3 <= _loc_4.overtimestr / 1000)
                        {
                            return true;
                        }
                    }
                    break;
                }
                case 5:
                {
                    _loc_6 = new Date();
                    _loc_6.setTime(_loc_3 * 1000);
                    _loc_7 = new Date(_loc_6.fullYear, _loc_6.month, _loc_6.date, 0, 0, 0, 0);
                    _loc_8 = new Date();
                    _loc_8.setTime(_loc_7.getTime() - (_loc_2 - 1) * 86400000);
                    if (_loc_8.getTime() >= _loc_4.sopentimestr && _loc_8.getTime() <= _loc_4.sovertimestr)
                    {
                        if (_loc_2 >= _loc_4.opentime && _loc_2 <= _loc_4.overtime)
                        {
                            return true;
                        }
                    }
                    else if (_loc_3 >= _loc_4.opentimestr / 1000 && _loc_3 <= _loc_4.overtimestr / 1000)
                    {
                        return true;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return false;
        }// end function

        public function openPluginF(param1:String, param2:Point, param3:Object = null, param4:Point = null) : void
        {
            var _loc_12:String = null;
            var _loc_5:* = UserData.getUserData();
            if (!UserData.getUserData())
            {
                return;
            }
            var _loc_6:* = _loc_5.mapid;
            var _loc_7:* = _loc_5.level;
            if (_loc_5.level < 55 && param1 == "rank")
            {
                ItemUilt.ErrortipsForLevel(55);
                return;
            }
            if (param1 == "xunbao")
            {
                if (this.isbaifuhd())
                {
                    param1 = "newxunbao";
                }
            }
            if (this._plugins[param1] == null)
            {
                return;
            }
            this._openDic[param1] = true;
            if (this._openArr.length >= 3)
            {
                this.closePlugin(this._openArr[0]);
            }
            var _loc_8:Boolean = false;
            var _loc_9:Array = [];
            var _loc_10:int = -1;
            var _loc_11:int = 0;
            while (_loc_11 < this._openArr.length)
            {
                
                if (this._openArr[_loc_11] == param1)
                {
                    _loc_8 = true;
                    _loc_10 = _loc_11;
                }
                _loc_11++;
            }
            for each (_loc_12 in _loc_9)
            {
                
                this.closePlugin(_loc_12);
            }
            if (!_loc_8)
            {
                this._openArr.push(param1);
            }
            else
            {
                this._openArr.splice(_loc_10, 1);
                this._openArr.push(param1);
            }
            this.tempPs[param1] = param2;
            this.tempdata[param1] = param3;
            this.tempTPs[param1] = param4;
            if (this._plugins[param1] is IPlugin)
            {
                this.open(param1, param2, param3, param4);
            }
            else if (this._plugins[param1] == UNLOAD)
            {
                this._plugins[param1] = OPEN;
                this.loadPlugin(param1);
            }
            else
            {
                this._plugins[param1] = OPEN;
            }
            var _loc_13:* = ModelProxy.getValue("localCache", "option");
            if (ModelProxy.getValue("localCache", "option") && _loc_13.offbasesound != 1)
            {
                ModelProxy.change("main", "playsound", "dz_1");
            }
            return;
        }// end function

        public function open(param1:String, param2:Point = null, param3:Object = null, param4:Point = null) : void
        {
            this._plugins[param1].open(param2, param3, param4);
            return;
        }// end function

        public function closeHandler(param1:String) : void
        {
            var _loc_2:String = null;
            var _loc_3:Boolean = false;
            XMLMcManager.instance.mcPluginDispose(param1);
            if (param1 != "bag" && this.getPluginState("bag") == OPEN)
            {
                _loc_3 = false;
                for each (_loc_2 in this.relation["bag"])
                {
                    
                    if (_loc_2 != param1 && this.getPluginState(_loc_2) == OPEN && this.openHandler(_loc_2))
                    {
                        return;
                    }
                    if (_loc_2 == param1)
                    {
                        _loc_3 = true;
                    }
                }
                if (_loc_3 && this._plugins["bag"].hasOwnProperty("returnToTemp"))
                {
                    this._plugins["bag"].returnToTemp();
                }
            }
            else if (param1 == "bag")
            {
                for each (_loc_2 in this.relation["bag"])
                {
                    
                    if (this.getPluginState(_loc_2) == OPEN)
                    {
                        if (this._plugins[_loc_2].hasOwnProperty("returnToTemp"))
                        {
                            this._plugins[_loc_2].returnToTemp();
                        }
                    }
                }
            }
            return;
        }// end function

        public function openHandler(param1:String) : Boolean
        {
            var _loc_2:int = 0;
            var _loc_3:Point = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:String = null;
            XMLMcManager.instance.mcload(param1);
            if (param1 == "roletwo" || this.getPluginState("roletwo") == OPEN)
            {
                for each (_loc_6 in this.relation["roletwo"])
                {
                    
                    if (this.getPluginState(_loc_6) == OPEN && param1 == "roletwo" || param1 == _loc_6)
                    {
                        if (this._plugins["roletwo"].hasOwnProperty("moveTo"))
                        {
                            _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[_loc_6].width + this._cfg["roletwo"].width)) / 2 + this._cfg[_loc_6].width;
                            _loc_3 = this.getDefaultPoint("roletwo");
                            this._plugins["roletwo"].moveTo(_loc_2, _loc_3.y);
                        }
                        if (this._plugins[_loc_6].hasOwnProperty("moveTo"))
                        {
                            _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[_loc_6].width + this._cfg["roletwo"].width)) / 2;
                            _loc_3 = this.getDefaultPoint(_loc_6);
                            this._plugins[_loc_6].moveTo(_loc_2, _loc_3.y);
                        }
                        return true;
                    }
                }
            }
            else if (param1 == "bag" || this.getPluginState("bag") == OPEN)
            {
                for each (_loc_6 in this.relation["bag"])
                {
                    
                    if (this.getPluginState(_loc_6) == OPEN && param1 == "bag" || param1 == _loc_6)
                    {
                        if (this._plugins["bag"].hasOwnProperty("moveTo"))
                        {
                            if (_loc_6 == "zbhsy" || _loc_6 == "qhtips")
                            {
                                _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[_loc_6].width + this._cfg["bag"].width)) / 2;
                            }
                            else if (_loc_6 == "role")
                            {
                                _loc_2 = (GlobalLayer.instance.root.stageWidth - (PluginManager._instance.getPlugin("role").width + this._cfg["bag"].width)) / 2 + PluginManager._instance.getPlugin("role").width;
                            }
                            else
                            {
                                _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[_loc_6].width + this._cfg["bag"].width)) / 2 + this._cfg[_loc_6].width;
                            }
                            _loc_3 = this.getDefaultPoint("bag");
                            this._plugins["bag"].moveTo(_loc_2, _loc_3.y);
                        }
                        if (this._plugins[_loc_6].hasOwnProperty("moveTo"))
                        {
                            if (_loc_6 == "zbhsy" || _loc_6 == "qhtips")
                            {
                                _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[_loc_6].width + this._cfg["bag"].width)) / 2 + this._cfg["bag"].width;
                            }
                            else if (_loc_6 == "role")
                            {
                                _loc_2 = (GlobalLayer.instance.root.stageWidth - (PluginManager._instance.getPlugin("role").width + this._cfg["bag"].width)) / 2;
                            }
                            else
                            {
                                _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[_loc_6].width + this._cfg["bag"].width)) / 2;
                            }
                            _loc_3 = this.getDefaultPoint(_loc_6);
                            if (_loc_6 == "qhtips")
                            {
                                this._plugins[_loc_6].moveTo(_loc_2, _loc_3.y - 110);
                            }
                            else
                            {
                                this._plugins[_loc_6].moveTo(_loc_2, _loc_3.y);
                            }
                        }
                        return true;
                    }
                }
            }
            return false;
        }// end function

        public function movePluginWithBag(param1:String) : void
        {
            var _loc_2:int = 0;
            var _loc_3:* = this.getDefaultPoint("bag");
            if (this._plugins["bag"].hasOwnProperty("moveTo"))
            {
                if (param1 != "zbhsy")
                {
                    if (param1 == "role")
                    {
                        _loc_2 = (GlobalLayer.instance.root.stageWidth - (PluginManager._instance.getPlugin("role").width + this._cfg["bag"].width)) / 2 + PluginManager._instance.getPlugin("role").width;
                    }
                    else
                    {
                        _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[param1].width + this._cfg["bag"].width)) / 2 + this._cfg[param1].width;
                    }
                }
                else
                {
                    _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[param1].width + this._cfg["bag"].width)) / 2;
                }
                _loc_3 = this.getDefaultPoint("bag");
                this._plugins["bag"].moveTo(_loc_2, _loc_3.y);
            }
            if (this._plugins[param1].hasOwnProperty("moveTo"))
            {
                if (param1 != "zbhsy")
                {
                    if (param1 == "role")
                    {
                        _loc_2 = (GlobalLayer.instance.root.stageWidth - (PluginManager._instance.getPlugin("role").width + this._cfg["bag"].width)) / 2;
                    }
                    else
                    {
                        _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[param1].width + this._cfg["bag"].width)) / 2;
                    }
                }
                else
                {
                    _loc_2 = (GlobalLayer.instance.root.stageWidth - (this._cfg[param1].width + this._cfg["bag"].width)) / 2 + this._cfg["bag"].width;
                }
                this._plugins[param1].moveTo(_loc_2, _loc_3.y);
            }
            return;
        }// end function

        public function getDefaultPoint(param1:String) : Point
        {
            var _loc_2:* = new Point();
            if (this._cfg[param1].left > 0)
            {
                _loc_2.x = this._cfg[param1].left;
            }
            else if (this._cfg[param1].right > 0)
            {
                _loc_2.x = GlobalLayer.instance.root.stageWidth - this._cfg[param1].width - this._cfg[param1].right;
            }
            else
            {
                _loc_2.x = (GlobalLayer.instance.root.stageWidth - this._cfg[param1].width) / 2;
            }
            if (this._cfg[param1].top > 0)
            {
                _loc_2.y = this._cfg[param1].top;
            }
            else if (this._cfg[param1].bottom > 0)
            {
                _loc_2.y = GlobalLayer.instance.root.stageHeight - this._cfg[param1].height - this._cfg[param1].bottom;
            }
            else
            {
                _loc_2.y = (GlobalLayer.instance.root.stageHeight - this._cfg[param1].height) / 2;
            }
            return _loc_2;
        }// end function

        public function getPluginState(param1:String) : String
        {
            if (this._plugins[param1] is String)
            {
                return this._plugins[param1];
            }
            if (this._plugins[param1])
            {
                return this._plugins[param1].visible ? (OPEN) : (CLOSE);
            }
            return this._plugins[param1];
        }// end function

        public function getPlugin(param1:String) : Object
        {
            return this._plugins[param1];
        }// end function

        public function getPluginSize(param1:String) : Point
        {
            return (this._plugins[param1] as FlashUIBase).getGuiSize();
        }// end function

        public function getPluginPos(param1:String) : Point
        {
            return (this._plugins[param1] as FlashUIBase).getGuiPostion();
        }// end function

        public function closePlugin(param1:String) : void
        {
            if (this._plugins[param1] == null)
            {
                return;
            }
            var _loc_2:int = 0;
            while (_loc_2 < this._openArr.length)
            {
                
                if (this._openArr[_loc_2] == param1)
                {
                    this._openArr.splice(0, 1);
                    break;
                }
                _loc_2++;
            }
            this._openDic[param1] = false;
            if (this._plugins[param1] is IPlugin)
            {
                IPlugin(this._plugins[param1]).close();
            }
            else if (this._plugins[param1] == OPEN)
            {
                this._plugins[param1] = CLOSE;
            }
            var _loc_3:* = ModelProxy.getValue("localCache", "option");
            if (_loc_3.offbasesound != 1)
            {
                ModelProxy.change("main", "playsound", "dz_2");
            }
            return;
        }// end function

        public function changePlugin(param1:String, param2:Point = null, param3:Object = null, param4:Point = null) : void
        {
            if (this._plugins[param1] == null)
            {
                return;
            }
            if (this._plugins[param1] != UNLOAD && this._plugins[param1] && this._plugins[param1].hasOwnProperty("visible") && this._plugins[param1].visible)
            {
                if (param1 == "role")
                {
                    if (param3 != 1)
                    {
                        this.closePlugin(param1);
                    }
                    else
                    {
                        this.openPlugin(param1, param2, param3, param4);
                    }
                }
                else
                {
                    this.closePlugin(param1);
                }
            }
            else
            {
                this.openPlugin(param1, param2, param3, param4);
            }
            return;
        }// end function

        public function loadPlugin(param1:String = null) : void
        {
            var _loc_3:Object = null;
            var _loc_4:PluginLoader = null;
            var _loc_5:ByteArray = null;
            if (param1 != null)
            {
                this._loadnames.push(param1);
            }
            if (this._isloading)
            {
                return;
            }
            if (this._loadnames.length <= 0)
            {
                return;
            }
            this._isloading = true;
            param1 = this._loadnames.shift();
            var _loc_2:* = this._localPlugins;
            if (_loc_2[param1])
            {
                _loc_3 = new _loc_2[param1];
                this.onComplete({name:param1, module:_loc_3});
            }
            else
            {
                _loc_4 = new PluginLoader();
                _loc_5 = ModelProxy.getValue("swfData", param1);
                if (!(param1 == "chatFlash" || param1 == "chat" || param1 == "welcome" || param1 == "flashupdate"))
                {
                    ModelProxy.change("progress", "progress", {name:"加载中...", type:3, cur:0, max:100});
                }
                if (_loc_5)
                {
                    _loc_4.loadPlugin(param1, _loc_5, this.onProgress, this.onComplete, false);
                }
                else
                {
                    _loc_4.loadPlugin(param1, this._cfg[param1].url, this.onProgress, this.onComplete, false);
                }
            }
            return;
        }// end function

        private function onProgress(param1:Object) : void
        {
            if (param1.name == "chatFlash" || param1.name == "chat" || param1.name == "welcome" || param1.name == "flashupdate")
            {
                return;
            }
            ModelProxy.change("progress", "progress", {name:"加载中...", type:3, cur:param1.progress, max:100});
            return;
        }// end function

        public function playItemSound(param1:Object) : void
        {
            var _loc_2:* = ModelProxy.getValue("localCache", "option");
            if (_loc_2.offbasesound != 1)
            {
                if (param1.cls == 1)
                {
                    ModelProxy.change("main", "playsound", SoundType.DZ_3);
                }
                else
                {
                    ModelProxy.change("main", "playsound", SoundType.DZ_6);
                }
            }
            return;
        }// end function

        public function loadAllPlugins() : void
        {
            return;
        }// end function

        public function playSound(param1:String) : void
        {
            var _loc_2:* = ModelProxy.getValue("localCache", "option");
            if (_loc_2.offbasesound != 1)
            {
                ModelProxy.change("main", "playsound", param1);
            }
            return;
        }// end function

        private function onComplete(param1:Object, param2:Boolean = false) : void
        {
            if (param1.name == "chatFlash" || param1.name == "chat" || param1.name == "welcome" || param1.name == "flashupdate")
            {
            }
            if (param1.hasOwnProperty("error") && param1.error == 1)
            {
                this.tempdata[param1.name] = null;
                delete this.tempdata[param1.name];
                delete this.tempPs[param1.name];
                delete this.tempTPs[param1.name];
                this._isloading = false;
                this.loadPlugin();
                this._plugins[param1.name] = UNLOAD;
                ModelProxy.change("progress", "complete", null);
                return;
            }
            this._plugins[param1.name] = param1.module;
            this._plugins[param1.name].install(this.getContainer(int(this._cfg[param1.name].type)), param1.name, this._cfg[param1.name].width, this._cfg[param1.name].height, this._cfg[param1.name].left, this._cfg[param1.name].right, this._cfg[param1.name].top, this._cfg[param1.name].bottom, this._cfg[param1.name].group);
            if (this._plugins[param1.name].hasOwnProperty("moveEff"))
            {
                this._plugins[param1.name].moveEff = this._cfg[param1.name].moveeff;
            }
            if (this._plugins[param1.name].hasOwnProperty("showTween"))
            {
                this._plugins[param1.name].showTween = this._cfg[param1.name].openaction == 1;
            }
            var _loc_3:* = this.tempPs[param1.name];
            if (!param2)
            {
                this.open(param1.name, _loc_3, this.tempdata[param1.name], this.tempTPs[param1.name]);
            }
            else
            {
                App.CurPluginName = param1.name;
                this._plugins[param1.name].preInitGui();
                App.CurPluginName = null;
            }
            this.tempdata[param1.name] = null;
            delete this.tempdata[param1.name];
            delete this.tempPs[param1.name];
            delete this.tempTPs[param1.name];
            this._isloading = false;
            this.loadPlugin();
            return;
        }// end function

        public function getGroupId(param1:String) : int
        {
            if (this._cfg[param1])
            {
                return this._cfg[param1].group;
            }
            return 0;
        }// end function

        public function refreshPluginsData(param1:Object) : void
        {
            return;
        }// end function

        public function sendToServer(param1:String, param2:int, param3:Object) : void
        {
            if (Config.Log > LogType.DEBUG)
            {
                Logger.log("发送功能请求:" + param1 + "," + param2 + "," + param3 + ",时间：" + getTimer());
            }
            var _loc_4:* = getTimer();
            this.messagelist.push(_loc_4);
            var _loc_5:* = this.messagelist[0];
            while (_loc_4 - _loc_5 > 1000)
            {
                
                _loc_5 = this.messagelist.shift();
            }
            if (this.messagelist.length > 20)
            {
                if (_loc_4 - this._lastwarning > 60000)
                {
                    Alert2.show("操作错误group:" + param1 + "cmd:" + param2, "发送请求过于频繁");
                    this._lastwarning = _loc_4;
                }
            }
            Server.instance.send(PluginManager.instance.getGroupId(param1), param2, param3, 0, ConnectType.SYSTEM);
            return;
        }// end function

        public function sendToBufferServer(param1:String, param2:int, param3:Output) : void
        {
            if (Config.Log > LogType.DEBUG)
            {
                Logger.log("发送buffer功能请求:" + param1 + "," + param2 + "," + ",时间：" + getTimer());
            }
            var _loc_4:* = getTimer();
            this.messagelist.push(_loc_4);
            var _loc_5:* = this.messagelist[0];
            while (_loc_4 - _loc_5 > 1000)
            {
                
                _loc_5 = this.messagelist.shift();
            }
            if (this.messagelist.length > 20)
            {
                if (_loc_4 - this._lastwarning > 60000)
                {
                    Alert2.show("操作错误group:" + param1 + "cmd:" + param2, "发送请求过于频繁");
                    this._lastwarning = _loc_4;
                }
            }
            Server.instance.sendBuffer(PluginManager.instance.getGroupId(param1), param2, param3 != null ? (param3.getBuffer()) : (null), 0, ConnectType.SYSTEM);
            return;
        }// end function

        public function sendMsg(param1:Object) : void
        {
            if (param1.group)
            {
                Server.instance.send(param1.group, param1.cmd, param1.param, 0, ConnectType.SYSTEM);
            }
            else
            {
                this.sendToServer(param1.name, param1.cmd, param1.param);
            }
            return;
        }// end function

        public function doRegister() : void
        {
            View.registerComponent("FlashItem", FlashItem);
            View.registerComponent("FlashS9Bg", FlashS9Bg);
            View.registerComponent("FlashS9TileBg", FlashS9TileBg);
            return;
        }// end function

        public function closeTop() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            var _loc_3:Object = null;
            if (GuideView.getInstance().visible == true)
            {
                GuideView.getInstance().hide(false);
            }
            if (this._alertCon.numChildren > 0)
            {
                _loc_1 = this._alertCon.numChildren;
                _loc_2 = _loc_1 - 1;
                while (_loc_2 >= 0)
                {
                    
                    _loc_3 = this._alertCon.getChildAt(_loc_2);
                    if (_loc_3.hasOwnProperty("groupName"))
                    {
                        if (_loc_3.hasOwnProperty("esc") && this._cfg[_loc_3.groupName].esc && _loc_3.visible)
                        {
                            _loc_3.esc();
                            return;
                        }
                    }
                    else if (_loc_3.hasOwnProperty("esc") && _loc_3.visible)
                    {
                        _loc_3.esc();
                        return;
                    }
                    _loc_2 = _loc_2 - 1;
                }
            }
            if (this._flashUiContainer.numChildren > 0)
            {
                _loc_1 = this._flashUiContainer.numChildren;
                _loc_2 = _loc_1 - 1;
                while (_loc_2 >= 0)
                {
                    
                    _loc_3 = this._flashUiContainer.getChildAt(_loc_2);
                    if (_loc_3.hasOwnProperty("esc") && this._cfg[_loc_3.groupName].esc && _loc_3.visible)
                    {
                        _loc_3.esc();
                        return;
                    }
                    _loc_2 = _loc_2 - 1;
                }
            }
            return;
        }// end function

        public static function get instance() : PluginManager
        {
            if (_instance == null)
            {
                _instance = new PluginManager;
            }
            return _instance;
        }// end function

    }
}
